using UnityEngine;
using System.Collections;

public class _Barrier : MonoBehaviour {
	
	public Vector2 size;
	public Texture texture;
	
	void Start () {
		
		gameObject.AddComponent("MeshRenderer");
		gameObject.AddComponent("MeshFilter");
	
		Mesh mesh = Quad.Create(size.x , size.y );
		gameObject.GetComponent<MeshFilter>().mesh = mesh;
		gameObject.GetComponent<MeshRenderer>().material = (Material) Resources.Load("Outros/Transparent");
		gameObject.GetComponent<MeshRenderer>().material.mainTexture = texture;
	
	}
	
	void Update () 
	{
		transform.Translate(_Speed.speed,0,0);
		
		if(transform.position.x < -40)
		{
			Destroy (gameObject);
		}

	}
	
	void OnCollisionEnter (Collision c)
	{
		if(c.gameObject.CompareTag("Player"))
		{
			Application.LoadLevel("SelecaoCenas");
		}
	}
	
	void OnCollisionStay(Collision c)
	{
		if(c.gameObject.CompareTag("Player"))
		{
			Application.LoadLevel("SelecaoCenas");
		}
	}
}
